layui.define(['jquery','table','element'],function(exports){
	var $ = layui.$
	,table = layui.table
	,element = layui.element
	,active = {
		deleteData: function(){
			var checkStatus = table.checkStatus('dataList')
			,data = checkStatus.data
			,len = data.length
			,arr=[];
			if(len<1){
				layer.msg('没有选中任何记录！');
				return;
			}
			layer.confirm('确定要删除选择的记录？', function(){
				for(var i=0; i<len; i++){arr.push(data[i].id);}
				window.location.href=catrgoryDelete+arr;
			});
		}
		,addData(){
			window.location.href=MyUrl.catrgoryAdd;	
		}
	}
	,obj = {
    	init: function(option){
			
			element.render();
			
			table.render({
				elem: '#dataList'
				,id : 'dataList'
				,url: MyUrl.catrgoryJsonList
				,cols: [[
					{type:'checkbox'}
					,{field:'id', width:80, title: 'ID',align: 'center', sort: true}
					,{field:'category_title', minwidth:500, title: '类别名称',sort: true}
					,{field:'created', width:150, align: 'center', title: '创建时间', templet: '#createdTpl' , sort: true}
					,{toolbar:'#bar',width:400, align: 'center', title: '操作'}
				]]
			});
			
			table.on('tool(dataFilter)', function(obj){
				var data = obj.data;
				if(obj.event === 'del'){
					layer.confirm('确定要删除这一条记录？', function(index){
						window.location.href=MyUrl.catrgoryDelete+data.id;	
					});
				} else if(obj.event === 'edit'){
					window.location.href=MyUrl.catrgoryEdit+data.id;	
				} else if(obj.event === 'add'){
					window.location.href=MyUrl.catrgoryAddSon+data.id;	
				} else if(obj.event === 'up'){
					window.location.href=MyUrl.catrgoryUp+data.id;	
				} else if(obj.event === 'down'){
					window.location.href=MyUrl.catrgoryDown+data.id;
				}
			});
		
			$('.demoTable .layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
				
		}
		
		
		
		
	};
	exports('category', obj);
});    